﻿using exMath.Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace exMath.Test
{
    
    
    /// <summary>
    ///This is a test class for FunctionsTest and is intended
    ///to contain all FunctionsTest Unit Tests
    ///</summary>
    [TestClass()]
    public class FunctionsTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for ToDomainIntervalArray
        ///</summary>
        [TestMethod()]
        public void ToIntervalArrayTest()
        {
            double[] Results = Functions.ToDomainIntervalArray(1.0, 3.0, 1.0);

            Assert.AreEqual(1.0, Results[0]);
            Assert.AreEqual(2.0, Results[1]);
            Assert.AreEqual(3.0, Results[2]);
        }

        private double sqr(double x)
        {
            return x * x;
        }

        /// <summary>
        ///A test for ExecuteFunction
        ///</summary>
        [TestMethod()]
        public void ExecuteFunctionTest()
        {
            //first with global function cache.

            double[] parameters = {1.0, 2.0, 3.0};
            double[] expected = { 1.0, 4.0, 9.0 };
            double[] Results = Functions.ExecuteFunction(parameters, sqr);

            Assert.AreEqual(1.0, Results[0]);
            Assert.AreEqual(4.0, Results[1]);
            Assert.AreEqual(9.0, Results[2]);

            //also with global function cache...
            GFC.PerformCaching = false;

            Results = Functions.ExecuteFunction(parameters, sqr);

            Assert.AreEqual(1.0, Results[0]);
            Assert.AreEqual(4.0, Results[1]);
            Assert.AreEqual(9.0, Results[2]);

            //enable the GFC before exiting the test.
            GFC.PerformCaching = true;

        }
    }
}
